const app = getApp();

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);
const store = new Vuex.Store({
	state: {
		hospitalList: [],
		departmentList: [],
	},
	mutations: {
		SET_HOSPITLlIST: (state, data) => {
			state.hospitalList = data
		},
		SET_DEPATMENTLIST: (state, data) => {
			state.departmentList = data
		}
	},
	actions: {
		getHospitalList({	commit	}) {
		return new Promise((resolve, reject)=>{
				uni.request({
					url: getApp().globalData.baseUrl+"org/sysorg/all",
					method: 'GET',
					header: {
						"token":getApp().globalData.token
					},
					success(res) {
						
						commit('SET_HOSPITLlIST', res.data.data)
						resolve(res.data.data);
					},
					fail(res) {
						console.log("失败",res);
						reject(error);
					}
				})
			});
		},
		getDepartmentList({	commit	},orgId) {
		return new Promise((resolve, reject)=>{
				uni.request({
					url:  getApp().globalData.baseUrl+"org/orgdept/deptAreas/"+orgId,
					method: 'GET',
					header: {
						"token":getApp().globalData.token
					},
					success(res) {
						commit('SET_DEPATMENTLIST', res.data.list)
						console.log("获取部门列表成功！", res);
						resolve(res.data.list);
					},
					fail(res) {
						console.log("失败",res);
						reject(error);
					}
				})
			});
		}
	}
});
export default store;